
cc.Class({
	extends: cc.Component,

	properties: {
		topNode: {
			default: null,
			type: cc.Node
		},

		realplayer: {
			default: null,
			type: cc.Node
		},


		nexttools: {
			default: null,
			type: cc.Node
		},


	},


	// LIFE-CYCLE CALLBACKS:

	onLoad() {
		



	},

	//显示升级界面--预制体
	showTip: function(event, customEventData) {
		
		//cc.log(isShow);
		
		
		var that = this;

		var CanvasNode = this.topNode;

		if (!CanvasNode) {
			cc.log('find Canvas error');
			return;
		}
		
		if(step!=7){
			
			var onResourceLoaded = function(errorMessage, loadedResource) {
			
				if (errorMessage) {
					cc.log('Prefab error:' + errorMessage);
					return;
				}
				if (!(loadedResource instanceof cc.Prefab)) {
					cc.log('Prefab error');
					return;
				}
			
				var newMyPrefab = cc.instantiate(loadedResource);
			
				CanvasNode.addChild(newMyPrefab, 100);
			
				newMyPrefab.setPosition(0, 0);
			
				var newMyPrefabScript = newMyPrefab.getComponent('AlertMsg');
			
			
			
				newMyPrefabScript.setLabelString(errormsg);
			
			
			};
								 
			if(isShow==0){
				isShow=!isShow;
				cc.resources.load('AlertMsg', onResourceLoaded);
				
			}
		}else{
		//===================================
		const sendData = {
			"TaskGuid": "slkdjflie09876",
			"DataType": "usergy",
			"userid": "1"
		}
		//获取网络数据
		let xhr = new XMLHttpRequest();
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
				var response = xhr.responseText;
				
				cc.log(response);
				let info = eval('(' + response + ')');
				let infores = eval('(' + info + ')');

				waittime = infores.setlog.waittime;
				waitminutes = infores.setlog.waitminutes;
				nowstep=infores.set.code;
				nextstep=infores.next_set.code;
				
				cc.log(infores);


				if (stepstatus == 0) {
					var onResourceLoaded = function(errorMessage, loadedResource) {
						if (errorMessage) {
							cc.log('Prefab error:' + errorMessage);
							return;
						}
						if (!(loadedResource instanceof cc.Prefab)) {
							cc.log('Prefab error');
							return;
						}


						var newMyPrefab = cc.instantiate(loadedResource);

						CanvasNode.addChild(newMyPrefab, 100);

						newMyPrefab.setPosition(0, 0);

						var newMyPrefabScript = newMyPrefab.getComponent('Alert');

						newMyPrefabScript.setLabelString("开始发酵！");

						newMyPrefabScript.onConfirBtn(function() {

							stepstatus = 1;
							//cc.log(stepstatus);
							//
							//cc.log('开始粉碎');

							//获取数据
							const sendData = {
								"TaskGuid": "slkdjflie09876",
								"DataType": "gameset",
								"user_id": "1",
								"set_code": "7",
								"status": "1"
							};

							//cc.log(sendData);
							//获取网络数据
							let xhr = new XMLHttpRequest();
							xhr.onreadystatechange = function() {
								if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
									var response = xhr.responseText;
									cc.log(response);
									//console.log("==============");	
									let info = eval('(' + response + ')');
									let infores = eval('(' + info + ')');


									cc.log(infores);

								}
							};

							// xhr.open("GET", seturl+'/'+JSON.stringify(sendData), true);
							xhr.open("GET", seturl + JSON.stringify(sendData), true);
							xhr.send();



						});
					};



					
					if(isShow==0){
						isShow=!isShow;
						cc.resources.load('Alert', onResourceLoaded);
					}
					


				} else {

					cc.log(waitminutes);
					if (waitminutes < 0 || waitminutes == 0) {

						//======
						var onResourceLoaded = function(errorMessage, loadedResource) {
							if (errorMessage) {
								cc.log('Prefab error:' + errorMessage);
								return;
							}
							if (!(loadedResource instanceof cc.Prefab)) {
								cc.log('Prefab error');
								return;
							}


							var newMyPrefab = cc.instantiate(loadedResource);

							CanvasNode.addChild(newMyPrefab, 100);

							newMyPrefab.setPosition(0, 0);

							var newMyPrefabScript = newMyPrefab.getComponent('Alert');

							newMyPrefabScript.setLabelString("好的，接下来开始蒸馏！");

							newMyPrefabScript.onConfirBtn(function() {
								step = 8;
						
								//获取数据
								const sendData = {
									"TaskGuid": "slkdjflie09876",
									"DataType": "gameset",
									"user_id": "1",
									"set_code": "7",
									"status": "2"
								};

								cc.log(sendData);
								//获取网络数据
								let xhr = new XMLHttpRequest();
								xhr.onreadystatechange = function() {
									if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
										var response = xhr.responseText;
										cc.log(response);
										//console.log("==============");	
										let info = eval('(' + response + ')');
										let infores = eval('(' + info + ')');


										cc.log(infores);

									}
								};

								// xhr.open("GET", seturl+'/'+JSON.stringify(sendData), true);
								xhr.open("GET", seturl + JSON.stringify(sendData), true);
								xhr.send();



							});
						};


						 
						if(isShow==0){
							isShow=!isShow;
							cc.resources.load('Alert', onResourceLoaded);
							
						}
						

						//======


					} else {

						var onResourceLoaded = function(errorMessage, loadedResource) {

							if (errorMessage) {
								cc.log('Prefab error:' + errorMessage);
								return;
							}
							if (!(loadedResource instanceof cc.Prefab)) {
								cc.log('Prefab error');
								return;
							}

							var newMyPrefab = cc.instantiate(loadedResource);

							CanvasNode.addChild(newMyPrefab, 100);

							newMyPrefab.setPosition(0, 0);

							var newMyPrefabScript = newMyPrefab.getComponent('AlertMsg');



							newMyPrefabScript.setLabelString('倒计时:' + waittime);


						};
					 
						if(isShow==0){
							isShow=!isShow;
							cc.resources.load('AlertMsg', onResourceLoaded);
							
						}
						
						//cc.loader.loadRes('background', onResourceLoaded );
					}
				}

			}
		};

		// xhr.open("GET", seturl+'/'+JSON.stringify(sendData), true);
		xhr.open("GET", url + JSON.stringify(sendData), true);
		xhr.send();
		//===================================
}
	},
	start() {

	},

	// update (dt) {},
});
